<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1" import="ass.beans.*" import="ass.dao.*"
	import="ass.dao.support.*" import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Friend requests</title>
</head>
<body>
	<%@ include file="header.html"%>
	<%@ include file="userNavBar.html"%>
	<%
		List<UserFriendsBean> userFriendsList    = (List<UserFriendsBean>) request.getAttribute("userFriendsList");
	    List<UserFriendsBean> userInvitationList = (List<UserFriendsBean>) request.getAttribute("userInvitationList");
	%>
	<div align="center">
	<%= (String) request.getAttribute("updated") == null ? "":(String) request.getAttribute("updated") %>
	
		<form action="updateFrdRqst" method="post">

			<table width="400" border="0">

				<!--     <td align="left">Tom</td>
    <td align="left">This is a friend request</td>
    <td><input type="submit" name="button" id="button" value="Accept"></td>
    <td><input type="submit" name="button2" id="button2" value="Reject"></td>
  </tr>
  <tr>
    <td align="left">Jerry</td>
    <td align="left">This is a friend request</td>
    <td><input type="submit" name="button3" id="button3" value="Accept"></td>
    <td><input type="submit" name="button4" id="button4" value="Reject"></td>
  </tr> -->

				<%
				out.print("<tr><th  align='left'>Nickname</th><th width='70' align='left'>Message</th><th  align='left'>Profile</th><th align='left'>Status</th><th align='left'>Action</th></tr>");

					if (userFriendsList.size() == 0) {
					//	out.print("<tr>");
					//	out.print("<td  rowspan='4'   align='center'>no friend requests at the moment!</td>");
					//	out.print("</tr>");
					} else {
					//	out.print("<tr><th  align='left'>Nickname</th><th  align='left'>Message</th><th  align='left'>Profile</th><th align='left'>Status</th><th align='left'>Action</th></tr>");
						for (UserFriendsBean userFrdBean : userFriendsList) {
							// out.print("<tr>");
							// out.print("  <td>"+ userFrdBean.getUsername() +"</td>");
							//
							//out.print("  <td>"+ userFrdBean.getMessage() +"</td>");
							// out.print("  <td><input type='submit' value='Accept'></td>");	
							// out.print("  <td><input type='submit' value='Reject'></td>");	  
							// out.print("</tr>");
							out.print("<tr>");
							out.print("  <td align='left'>" + userFrdBean.getUsername() + "</td>");
							out.print("  <td align='left'>" + userFrdBean.getMessage() + "</td>");
							out.print("  <td align='left'><a href='userFrdSearchDetail.jsp?username="
									+ userFrdBean.getUsername()
									+ "'>View Detail</a></td>");
							if (!userFrdBean.isAccepted() && !userFrdBean.isRejected())
								out.print("  <td align='left'>Pending</td>");	
							else if (userFrdBean.isAccepted())
								out.print("  <td align='left'>Accepted</td>");	
							else if (userFrdBean.isRejected())
								out.print("  <td align='left'>Rejected</td>");	
							
							if ( !(userFrdBean.isAccepted() || userFrdBean.isRejected())) {
							out.print(" <td align='left'> " +
									  " <a href='updateFrdRqst?username="+userFrdBean.getUsernameFriend()+"&usernameFriend="+userFrdBean.getUsername()+"&status=accept'>Accept</a>"+ 
									  " or" + 
									  " <a href='updateFrdRqst?username="+userFrdBean.getUsernameFriend()+"&usernameFriend="+userFrdBean.getUsername()+"&status=reject'>Reject</a></td>");
							out.print("</tr>");
							}
						}
					}
				%>

<!--</table>
		</form>
		
		<br>

		<table width="400" border="0">  -->			
		
		<%
					if (userInvitationList.size() == 0) {
					//	out.print("<tr>");
					//	out.print("<td  rowspan='4'  align='center'>no friend requests at the moment!</td>");
					//	out.print("</tr>");
					} else {
					//	out.print("<tr><th align='left'>Nickname</th><th align='left'>Message</th><th align='left'>Profile</th><th align='left'>Status</th></tr>");
						for (UserFriendsBean userFrdBean : userInvitationList) {
							// out.print("<tr>");
							// out.print("  <td>"+ userFrdBean.getUsername() +"</td>");
							//
							//out.print("  <td>"+ userFrdBean.getMessage() +"</td>");
							// out.print("  <td><input type='submit' value='Accept'></td>");	
							// out.print("  <td><input type='submit' value='Reject'></td>");	  
							// out.print("</tr>");
							out.print("<tr>");
							out.print("  <td align='left'>" + userFrdBean.getUsernameFriend() + "</td>");
							out.print("  <td align='left'>" + userFrdBean.getMessage() + "</td>");
							out.print("  <td align='left'><a href='userFrdSearchDetail.jsp?username="
									+ userFrdBean.getUsernameFriend()
									+ "'>View Detail</a></td>");
							if (!userFrdBean.isAccepted() && !userFrdBean.isRejected())
								out.print("  <td align='left'>Pending</td>");	
							else if (userFrdBean.isAccepted())
								out.print("  <td align='left'>Accepted</td>");	
							else if (userFrdBean.isRejected())
								out.print("  <td align='left'>Rejected</td>");	
						}
					}
				%>
		
		
		</table>
		
	</div>
</body>
</html>